package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;


    @Override
    public PageBean find(String name, Short gender, LocalDateTime begin, LocalDateTime end, Integer page, Integer pagesize) {
        PageHelper.startPage(page, pagesize);
        List<Emp> emps=empMapper.find(name,gender,begin,end);
        Page<Emp> p=(Page<Emp>)emps;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void add(Emp emp) {
        empMapper.add(emp);
    }

    @Override
    public void update(Emp emp) {
        empMapper.update(emp);

    }

    @Override
    public Emp findById(Integer id) {
        return empMapper.findById(id);
    }

    @Override
    public void DeleteByDeptID(Integer id) {
        empMapper.DeleteByDeptID(id);
    }

    @Override
    public Emp FindByUsernameAndPassword(Emp emp) {
        return empMapper.FindByUsernameAndPassword(emp);
    }
}
